Repository navigation
FIX open streams filter by the auth data of the connect instead of the current one - #482
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015P6w6gSU5X3tPquwWNPFbs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015P6w6gSU5X3tPquwWNPFbs
✅ Verify Test Reproduction: Tests FAILED without the fix (expected)This confirms the changed tests correctly reproduce the bug that the source changes fix. This workflow runs the changed tests without the source fix to verify they reproduce the bug. Show output |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015P6w6gSU5X3tPquwWNPFbs
|
I pushed a follow-up commit. With this PR, the document matcher is built inside the stream for every event. When the endpoint's Both routes now end the stream when building the matcher throws, the same way they do when the Generated by Claude Code |
Bug
The SSE routes
/pullStream(replication endpoint) and/query/observe(REST endpoint) call theauthHandleragain before every event. But the result was only used to detect an expired or invalid auth:/pullStreamthe fresh auth data went into a local variable that was never read./query/observethe reassignedauthDatawas never used.The documents were still filtered by the
queryModifierwith the auth data of the connect.So when the auth data for the same headers changes while a stream is open, the stream keeps sending documents the user may no longer see. For example, the
authHandlerlooks up the user's team in a database and the user is removed from the team./pulland/queryalready use the current auth data on every request.Fix
Both routes now build the document matcher (
getDocAllowedMatcher) from the current auth data on every event and filter with it, before the server-only fields are removed.For
/query/observe, the RxQuery still runs with the query that was modified at connect time. Its results are additionally filtered by the current matcher. Documents the user lost access to are removed right away. Documents the user newly gained access to appear after a reconnect. Ending the stream whenever the modified query changes was not used, because aqueryModifierthat usesDate.now()would make it reconnect endlessly.Tests
endpoint-replication.test.ts: should use the current auth data to filter the events of an open pullStreamendpoint-rest.test.ts: should use the current auth data to filter the results of an open streamBoth change the auth data of an open stream and fail without the fix.
Full unit suite: 109 passing.
npm run check-typespasses. An independent review confirmed the bug, the fix, and the order of matching before removing server-only fields. It ran the new tests 15 times with no failures.Changelog:
orga/changelog/fix-stream-fresh-auth.mdGenerated by Claude Code